<script>
export default {
  name: 'Test_Component2',
  data() {
    return {
      isShow: true,
      showClass: '',
    }
  },
  methods: {
    showOrHide() {
      this.isShow = !this.isShow;
    }
  }
}
</script>

<template>
  <div>
    <!--    使用过渡-->
    <button @click="showOrHide">显示/隐藏</button>
<!--    <transition name="h1Show" appear>-->
<!--      <h1 v-show="isShow">HELLO,WORLD</h1>-->
<!--    </transition>-->
<!--多个元素过渡 需要使用transition-group标签 并且给元素添加key值-->
    <transition-group name="h1Show" appear>
      <h1 v-show="!isShow" key="1">HELLO,WORLD</h1>
      <h1 v-show="isShow" key="2">HELLO,WORLD2</h1>
    </transition-group>
  </div>
</template>

<style scoped>
h1 {
  color: white;
  background-color: darkblue;
  text-align: center;
}

/* 给transition添加过渡时间 */
.h1Show-leave-active, .h1Show-enter-active {
  transition: 0.5s linear;
}

.h1Show-leave, .h1Show-enter-to {
  transform: translateX(0);

}

.h1Show-enter, .h1Show-leave-to {
  transform: translateX(-100%);
}


</style>